package pro.survey.analyzer.note.window;

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBoxBuilder;
import javafx.stage.Modality;
import javafx.stage.Stage;
import pro.survey.analyzer.GUIGenerator;
import pro.survey.analyzer.Trans;

/**
 *
 * @author Adrian
 */
public class NoteWindow {

    private Stage dialogStage;
    private TextArea textarea;
    private ButtonOK buttonOK;
    private ButtonCancel buttonCancel;
    private static NoteWindow instance = null;
    private Label label;

    /**
     *
     * @return ImportsWindow
     */
    public static NoteWindow getInstance() {
        if (instance == null) {
            instance = new NoteWindow();
        }
        return instance;
    }

    private NoteWindow() {
    }

    public void init(Label label) {
        this.label = label;
        dialogStage = new Stage();
        buttonOK = new ButtonOK(dialogStage);
        buttonCancel = new ButtonCancel(dialogStage);
        dialogStage.initModality(Modality.APPLICATION_MODAL);
        textarea = new TextArea();
        if (label.getText().length() > 0)
            textarea.setText(label.getText().substring(11));
        BorderPane bp = new BorderPane();
        bp.setBottom(HBoxBuilder.create().spacing(10).
                alignment(Pos.CENTER).children(buttonOK, buttonCancel).
                padding(new Insets(10)).build());
        bp.setCenter(textarea);
        Scene dialogScene = new Scene(bp);
        dialogStage.setScene(dialogScene);
        dialogStage.show();
    }

    public ButtonOK getButtonOK() {
        return buttonOK;
    }

    public ButtonCancel getButtonCancel() {
        return buttonCancel;
    }

    public TextArea getTextarea() {
        return textarea;
    }

    public void setTextarea(TextArea textarea) {
        this.textarea = textarea;
    }
    
    public void updateNote() {
        if (textarea.getText().length() > 0)
            label.setText(GUIGenerator.getInstance().getLocaleText(Trans.COMMENT).concat(" ").concat(textarea.getText()));
        else
            label.setText(textarea.getText());
    }
}

